<?php

namespace App\Http\Requests\Client\Work;

use App\Exceptions\GeneralException;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Auth;

class WorkEntry extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     * @throws GeneralException
     */
    public function authorize()
    {
        $user = Auth::guard('courier')->user();
        // 判断是有权限入库  0入库  1派件  2所有权限
        if ($user->jurisdiction == 0) {
            return true;
        } else {
            throw new GeneralException('您没入库权限', 403);
        }
    }

    /**
     * 定义表单规则
     *
     * Date: 2018/05/25
     * @author Tenny
     * @return array
     */
    public function rules()
    {
        return [
            'order_id' => 'required|integer',
        ];
    }

    /**
     * 定义错误响应消息
     *
     * Date: 2018/05/25
     * @author Tenny
     * @return array
     */
    public function messages()
    {
        return [
            'order_id.required' => '请上传订单id',
            'order_id.integer' => '请上传正确的订单id',
        ];
    }
}
